"""
微信自动发送信息
"""
import subprocess
import uiautomation as auto

'''
微信安装路径
'''
subprocess.Popen('D:\微信\WeChat\WeChat.exe')

wechatWindow = auto.WindowControl(searchDepth=1, className='WeChatMainWndForPC', Name='微信')
'''
a表示联系人备注列表，b表示要发送的内容
'''
a = ['']
b = '你好'

'''
遍历联系人列表
'''
for i in a:

    search = wechatWindow.EditControl(Name='搜索')
    search.Click()

    search.GetParentControl().GetChildren()[1].SendKeys(i)
    searResult = wechatWindow.ListControl(Name='搜索结果').GetChildren()
    for sear in searResult:
        if sear.Name == i:
            sear.Click()
            break

    wechatWindow.EditControl(Name='输入').SendKeys(b)
    wechatWindow.SendKeys('{Enter}')
    print(i, ' 消息已发送')